package p100;

public class Leetcode_108 {
    /**
     * Definition for a binary tree node.
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public TreeNode sortedArrayToBST(int[] nums) {
        return nums == null ? null : buildTree(nums, 0, nums.length - 1);
    }

    private TreeNode buildTree(int[] nums, int i, int j) {
        if (i > j) {
            return null;
        }
        int m = i + (j - 1) / 2;
        TreeNode root = new TreeNode(nums[m]);
        root.left = buildTree(nums, i, m - 1);
        root.right = buildTree(nums, m + 1, j);
        return root;
    }

    public static void main(String[] args) {
        System.out.println();
    }
}
